package com.study_security.controller;

import com.study_security.domain.LoginUser;
import com.study_security.dto.UserDTO;
import com.study_security.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api/userinfo")

public class UserController {

    @Autowired
    UserMapper userMapper;

    /**
     * 用于获得用户的基本信息
     * @param authentication
     * @return  UserDTO
     */
    @GetMapping
    public UserDTO getUserInfo(Authentication authentication){
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Long userId = loginUser.getUser().getId();
        return  userMapper.selectUserInfoById(userId);
    }


}